public class ArraySorting {

	public void sortTheArry(int[] a) {
		/*
		 * int newArray [] = new int[arr.length]; int max = arr.length-1; int
		 * min = 0; for(int bit : arr){ if(bit ==1) newArray[max--] = 1; else
		 * newArray[min++] = 0; } for(int i=0;i<newArray.length;i++){
		 * System.out.print(newArray[i]+" "); }
		 */
		int i = 0;
		int j = a.length - 1, temp;
		while (j >= i) {
			if (a[i] == 1 && a[j] == 0) {
				temp = a[j];
				a[j] = a[i];
				a[i] = temp;
			}
			if (a[i] == 0)
				i++;
			if (a[j] == 1)
				j--;
		}
		for (int i1 : a) {
			System.out.print(i1 + " ");
		}
	}

	public static int[] sortA(int[] ar) {
		int start = 0;
		int mid = 0;
		for (int i = 0; i < ar.length; i++) {
			if (ar[mid] == 0) {
				ar[mid] = 1;
				ar[start] = 0;
				start++;
				mid++;

			} else if (ar[mid] == 1) {
				mid++;
			}
		}

		return ar;
	}

	public static int[] sortB(int[] ar) {
		int start = 0;
		int mid = 0;
		int end = ar.length - 1;
		while (mid <= end) {
			if (ar[mid] == 0) {
				ar[mid] = 1;
				ar[start] = 0;
				start++;
				mid++;

			} else if (ar[mid] == 1) {
				mid++;
			} else if (ar[mid] == 2) {
				ar[mid] = ar[end];
				ar[end] = 2;
				end--;

			}
		}

		return ar;
	}

	public static int secondHighest(int[] ar) {
		int highest = ar[0];
		int sencon = 0;
		for (int i = 0; i < ar.length - 1; i++) {
			if (ar[i + 1] > highest) {
				sencon = highest;
				highest = ar[i + 1];
			} else if (ar[i + 1] < highest && ar[i + 1] > sencon) {

				sencon = ar[i + 1];
			}
		}

		return sencon;
	}

	public static void main(String[] args) {
		ArraySorting aa = new ArraySorting();
		int a[] = { 1, 2, 10, 0, 3, 1, 0, 1, 0 };
		// System.out.println(Arrays.toString(sortB(a)));
		System.out.println(secondHighest(a));

		// aa.sortTheArry(a);
	}
}
